#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MVNum = 3;
typedef string VertexType;
typedef struct ArcNode
{
    int adjvex;
    struct ArcNode *nextarc;
} ArcNode;
typedef struct VNode
{
    VertexType data;   // 顶点信息
    ArcNode *firstarc = NULL; // 指向第一条依附该顶点的弧
} VNode, AdjList[MVNum];
typedef struct
{
    AdjList vertice;
    int vexnum, arcnum;
} ALGraph;

void createadjlist(ALGraph &G)
{
    cin >> G.vexnum >> G.arcnum;
    for (int i = 0; i < G.vexnum; i++)
    {
        cin >> G.vertices[i].data;
        G.vertices[i].firstarc = NULL;
    }
    ArcNode *s = NULL;
    for (int k = 0; k < G.arcnum; k++)
    {
        int i, j;
        cin >> i >> j;
        s = new ArcNode;
        s->adjvex = j;
        s->nextarc = G.vertices[i].firstarc;
        G.vertices[i].firstarc = s;
        s = new ArcNode;
        s->adjvex = i;
        s->nextarc = G.vertices[j].firstarc;
        G.vertices[j].firstarc = s;
    }
}
int main(int argc, char const *argv[])
{
    ALGraph G;
    createadjlist(G);
    for (int i = 0; i < G.vexnum; i++)
    {
        ArcNode *p = G.vertices[i].firstarc;
        cout << G.vertices[i].data;
        while (p != NULL)
        {
            cout << " -> " << p->adjvex;
            p = p->nextarc;
        }

        cout << " -> NULL" << endl;
        
    }
    
    return 0;
}
